package me.leiusual.sharing.ui.setting

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.pref.Token
import me.leiusual.sharing.repository.PlatformRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/15
 */
class SettingHomeViewModel @Inject constructor(
    private val platformRepository: PlatformRepository,
    val token: Token
) : ViewModel() {

  private val _clearCache = MutableLiveData<Unit>()
  val clearCache: LiveData<Data<Unit>> = Transformations.switchMap(_clearCache) {
    platformRepository.clearCache().toLiveData()
  }

  fun clearCache() {
    _clearCache.value = Unit
  }
}